package com.huiquan.vocab.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.huiquan.framework.base.ReturnData;
import com.huiquan.framework.utils.ReturnUtil;
import com.huiquan.vocab.domain.HiveSymptomDyadStd;
import com.huiquan.vocab.service.VocabDyadSymptomService;
import com.huiquan.vocab.utils.SymptomStdDyadUtil;

@Controller
public class VocabDyadSymptomController {

	@Autowired
	private SymptomStdDyadUtil symptomStdDyadUtil;
	@Autowired
	private VocabDyadSymptomService vocabDyadSymptomService;

	@ResponseBody
	@RequestMapping(value = "/vocab/get_symptom_std_dyad.do")
	public String getSymptomStdDyad(HttpServletRequest req, HttpServletResponse resp) {

		String symptomArray = req.getParameter("symptomArray");
		String partPattern = req.getParameter("partPattern");
		String cnt = req.getParameter("cnt");

		List<HiveSymptomDyadStd> list = symptomStdDyadUtil.getSymptomStd(symptomArray, partPattern, cnt);
		StringBuffer result = new StringBuffer();
		for (HiveSymptomDyadStd temp : list) {
			result.append(temp.getSymptom());
			result.append("\t");
			result.append(temp.getSymptomArray());
			result.append("\t");
			result.append(temp.getPartPattern());
			result.append("\t");
			result.append(temp.getStdSymptom());
			result.append("\t");
			result.append(temp.getStdSymptomArray());
			result.append("\t");
			result.append(temp.getStdPartPattern());
			result.append("\t");
			result.append(temp.getDyadStdArray());
			result.append("\t");
			result.append(temp.getDyadStdPartPattern());
			result.append("\t");
			result.append(temp.getCnt());
			result.append("\n");
		}
		if (result.length() == 0) {
			result.append("empty");
		}

		return result.toString();
	}

	@ResponseBody
	@RequestMapping(value = "/vocab/get_std_dyad_by_file.do")
	public ReturnData getStdDyadByFile(HttpServletRequest req, HttpServletResponse resp) throws Exception {

		String inputPath = req.getParameter("input");
		String type = req.getParameter("type");

		if (type != null && "1".equals(type)) {
			// 第一种类型，每日任务获取症状标准词提交到181
			vocabDyadSymptomService.exportSymptomStdDyadTo181();
		} else if (type != null && "2".equals(type)) {
			// 第二种类型，本地根据传入的文件地址，将症状标准词生成后导出到相同位置
			vocabDyadSymptomService.localGetSymptomStdDyadByBatch(inputPath, type);
		}

		return ReturnUtil.success();
	}

}
